package test.redis;
import java.util.ArrayList;
import java.util.List;

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
import redis.clients.util.Hashing;
import redis.clients.util.Sharded;
public class JedisUtil {
	public static ShardedJedisPool pool;
	    static{
	        JedisPoolConfig config =new JedisPoolConfig();//Jedis池配置
	        config.setMaxIdle(50);//最大活动的对象个数
          config.setMaxIdle(1000 * 60);//对象最大空闲时间
          config.setMaxWaitMillis(3000 * 10);//获取对象时最大等待时间
          config.setMaxTotal(5000);
         // config.setTestOnBorrow(true);
	        String hostA = "192.168.2.129";
	          int portA = 6379;
	        List<JedisShardInfo> jdsInfoList =new ArrayList<JedisShardInfo>();
	        JedisShardInfo infoA = new JedisShardInfo(hostA, portA);
	       infoA.setPassword("root");
	        jdsInfoList.add(infoA);
	       
	        pool =new ShardedJedisPool(config, jdsInfoList, Hashing.MURMUR_HASH,Sharded.DEFAULT_KEY_TAG_PATTERN);
	    }
	   
	    /**
	     * @param args
	     */
	    public static void main(String[] args) {
	           ShardedJedis jds =null;
	           try {
	               jds =pool.getResource();
	               long setnx = jds.hset("xx", "a", "ab");
	               System.out.println(setnx);
	           }catch (Exception e) {
	               e.printStackTrace();
	           }
	           finally{
	        	   jds.close();
	           }
	    }
	 
}

